//
//  WBTableViewDataSource.m
//
//  Created by 周佳兴 on 16/3/9.
//  Copyright © 2016年 周佳兴. All rights reserved.
//

#import "WBTableViewDataSource.h"
#import "WBTableViewCell.h"
#import "Masonry.h"
@interface WBTableViewDataSource ()

@property (nonatomic, copy) TableViewCellConfigureBlock configureCellBlock;
@property (nonatomic, strong) Class Cellclass;
@property (nonatomic, strong) NSArray * modelArray;

@end
@implementation WBTableViewDataSource

- (instancetype) init {
    
    if (self = [super init]) {
        
    }
    return self;
}

- (instancetype) initWithItems:(NSArray *)anItems
                     cellClass:(Class)cellClass
            configureCellBlock:(TableViewCellConfigureBlock)aConfigureCellBlock {
    
    if (self = [super init]) {
        
        self.modelArray = anItems;
        self.configureCellBlock = [aConfigureCellBlock copy];
        self.Cellclass = cellClass;
    }
    return self;
}



- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.modelArray.count;
}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    WBTableViewCell * cell = [[self.Cellclass class]cellAllocWithTableView:tableView];
    self.configureCellBlock(cell,self.modelArray[indexPath.row]);
    
    
    
    //    [cell.textLabel mas_updateConstraints:^(MASConstraintMaker *make) {
    //        make.centerX.equalTo(cell.contentView.mas_centerX);
    //        make.centerY.equalTo(cell.contentView.mas_centerY);
    //    }];
    [cell.textLabel sizeToFit];
    //    [cell.imageView mas_updateConstraints:^(MASConstraintMaker *make) {
    //        make.right.equalTo(cell.textLabel.mas_left);
    //        make.centerY.equalTo(cell.contentView.mas_centerY);
    //    }];
    
    return cell;
}

@end
